package com.delivery.www.service.ServiceImpl;

import com.delivery.www.dao.DishDao;
import com.delivery.www.dao.DaoImpl.DishDaoImpl;
import com.delivery.www.po.Dish;
import com.delivery.www.service.DishService;
import com.delivery.www.util.JdbcUtils;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class DishServiceImpl implements DishService {
    private DishDao dishDao;

    public DishServiceImpl() {
        dishDao = new DishDaoImpl();
    }

    @Override
    public List<Dish> getDish(int storeId) {
        List<Dish> dishes = null;
        dishes = dishDao.getDish(storeId);
        return dishes;
    }

    @Override
    public boolean addDish(String dishName, int storeId, Float price, String describe) {
        boolean flag = false;
        int i = dishDao.addDish(dishName, storeId, price, describe);
        if (i > 0) {
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean updateDishName(String oldName, String newName) {
        boolean flag = false;
        int i = dishDao.updateDishName(oldName, newName);
        if (i > 0) {
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean updateDishPrice(String oldName, Float price) {
        boolean flag = false;
        int i = dishDao.updateDishPrice(oldName, price);
        if (i > 0) {
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean updateDishDescribe(String oldName, String introduce) {
        boolean flag = false;
        int i = dishDao.updateDishDescribe(oldName, introduce);
        if (i > 0) {
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean deleteDish(String name, int storeId) {
        boolean flag = false;
        int i = dishDao.deleteDish(name, storeId);
        if (i > 0) {
            flag = true;
        }
        return flag;
    }

    @Override
    public Dish getOneDish(int dishId) {
        Dish dish = null;
        dish = dishDao.getOneDish(dishId);
        return dish;
    }
}
